home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto03 / ufmgr12.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-03-06  |  30.9 KB  |  869 lines

  1. unit Ufmgr12;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl,
  8.    DRWSUtl1, DRWSUtl3;
  9.  
  10. type
  11.   TCCFileMgrForm = class(TForm)
  12.     Panel1: TPanel;
  13.     Panel2: TPanel;
  14.     BitBtn1: TBitBtn;
  15.     Panel3: TPanel;
  16.     Label1: TLabel;
  17.     BitBtn2: TBitBtn;
  18.     BitBtn3: TBitBtn;
  19.     BitBtn4: TBitBtn;
  20.     BitBtn5: TBitBtn;
  21.     BitBtn6: TBitBtn;
  22.     BitBtn7: TBitBtn;
  23.     OpenDialog1: TOpenDialog;
  24.     BitBtn8: TBitBtn;
  25.     BitBtn9: TBitBtn;
  26.     OpenDialog2: TOpenDialog;
  27.     BitBtn10: TBitBtn;
  28.     procedure FormResize(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure BitBtn7Click(Sender: TObject);
  31.     procedure BitBtn1Click(Sender: TObject);
  32.     procedure BitBtn2Click(Sender: TObject);
  33.     procedure BitBtn3Click(Sender: TObject);
  34.     procedure BitBtn4Click(Sender: TObject);
  35.     procedure BitBtn5Click(Sender: TObject);
  36.     procedure FormPaint(Sender: TObject);
  37.     procedure BitBtn8Click(Sender: TObject);
  38.     procedure BitBtn9Click(Sender: TObject);
  39.     procedure BitBtn6Click(Sender: TObject);
  40.     procedure BitBtn1DragDrop(Sender, Source: TObject; X, Y: Integer);
  41.     procedure BitBtn1DragOver(Sender, Source: TObject; X, Y: Integer;
  42.       State: TDragState; var Accept: Boolean);
  43.     procedure BitBtn2DragDrop(Sender, Source: TObject; X, Y: Integer);
  44.     procedure BitBtn3DragDrop(Sender, Source: TObject; X, Y: Integer);
  45.     procedure BitBtn4DragDrop(Sender, Source: TObject; X, Y: Integer);
  46.     procedure BitBtn10Click(Sender: TObject);
  47.     procedure FormDestroy(Sender: TObject);
  48.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  49.       Shift: TShiftState);
  50.   private
  51.     { Private declarations }
  52.   public
  53.     { Public declarations }
  54.     DirectoryListBox1 : TDirectoryListBox;
  55.     FileListBox1 : TIconFileListBox;
  56.     ScrollBox1 : TFileIconPanelScrollbox;
  57.   end;
  58. var
  59.   CCFileMgrForm      : TCCFileMgrForm;
  60.   CurrentView        : Integer;  { This holds the current view setting      }
  61.  
  62. implementation
  63.  
  64. {$R *.DFM}
  65.  
  66. uses DDDFUnit,  { Include custom directory selection form }
  67.      CfmpfUn;   { Include custom options dialog           }
  68.  
  69. { Set up the resize to replace the icon buttons }
  70. procedure TCCFileMgrForm.FormResize(Sender: TObject);
  71. begin
  72.   { Send in the panel and global buttons list }
  73.   SpacePanelButtons( Panel2 );
  74. end;
  75.  
  76. { Delphi wrote this; use it to set everything up }
  77. procedure TCCFileMgrForm.FormCreate(Sender: TObject);
  78. var TheIconPanel : TFileIconPanel;
  79.     CurrentPath : String;
  80. begin
  81.   { Create the directory list box }
  82.   DirectoryListBox1 := TDirectoryListBox.Create( Panel1 );
  83.   DirectoryListBox1.Parent := Panel1;
  84.   DirectoryListBox1.Visible := true;
  85.   DirectoryListbox1.Top := 17;
  86.   DirectoryListbox1.Left := 0;
  87.   DirectoryListbox1.Height := Panel1.Height - 32;
  88.   DirectoryListbox1.Width := 0;
  89.   { Create the file list box }
  90.   FileListBox1 := TIconFileListBox.Create( Panel1 );
  91.   FileListBox1.Parent := Panel1;
  92.   FileListbox1.Top := 17;
  93.   FileListbox1.Left := 146;
  94.   FileListbox1.Height := Panel1.Height - 32;
  95.   FileListbox1.Width := 0;
  96.   FileListBox1.Visible := true;
  97.   FileListBox1.ShowGlyphs := true;
  98.   FileListBox1.MultiSelect := true;
  99.   FileListBox1.DragMode := dmAutomatic;
  100.   { Set intercomponent interactions }
  101.   DirectoryListBox1.FileList := FileListbox1;
  102.   DirectoryListBox1.DirLabel := Label1;
  103.   { Create the scrollbox }
  104.   ScrollBox1 := TFileIconPanelScrollBox.Create( Panel1 );
  105.   ScrollBox1.Parent := Panel1;
  106.   ScrollBox1.align := alClient;
  107.   ScrollBox1.Left := 0;
  108.   ScrollBox1.Top := 0;
  109.   ScrollBox1.Width := Panel1.Width - 32;
  110.   ScrollBox1.Height := Panel1.Height - 32;
  111.   ScrollBox1.IconsNeedRefreshing := false;
  112.   ScrollBox1.TheStoredHandle := Self.Handle;
  113.   ScrollBox1.TheParentForm := Self;
  114.   { Get the current directory with 0 parameter }
  115.   GetDir( 0 , CurrentPath );
  116.   { Set the display caption }
  117.   Label1.Caption := CurrentPath;
  118.   { Add a trailing \ if not root }
  119.   CurrentPath := ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentPath );
  120.   { Get the icons display using scrollbox1 }
  121.   ScrollBox1.GetIconsForEntireDirectory( CurrentPath );
  122.   { Set the Icon View as default }
  123.   CurrentView := 1;
  124.   { Start the FIP IOManager }
  125.   if not assigned( TheIOManager ) then
  126.   begin
  127.     TheIOManager := TIOManager.Create( Self );
  128.     TheIOManager.Parent := Self;
  129.   end;
  130. end;
  131.  
  132. { Delphi wrote this; use it to close the application }
  133. procedure TCCFileMgrForm.BitBtn7Click(Sender: TObject);
  134. begin
  135.   Close;
  136. end;
  137.  
  138. { Delphi wrote this use it to perform a copy on all selected files }
  139. procedure TCCFileMgrForm.BitBtn1Click(Sender: TObject);
  140. var ThePosition  : Integer;       { Loop counter   }
  141.     CurrentName ,                 { Holds work name}
  142.     TheOldString : String;        { Holds Dir      }
  143.     finished     : Boolean;       { Loop control   }
  144.     WorkingDir   : String;        { Holds mod wd   }
  145.     TargetDir    : String;        { target of op   }
  146.     TheResult    : Integer;       { Modal res hold }
  147. begin
  148.   { Get current directory and save it for later }
  149.   GetDir( 0 , TheOldString );
  150.   { Check for need to add trailing \ }
  151.   WorkingDir := TheOldString;
  152.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  153.   { Display the Windows-based directory input form }
  154.   TheResult := DestDDForm.ShowModal;
  155.   { If not cancelled do the copy }
  156.   if TheResult = mrOK then
  157.   begin
  158.     { Get the target directory with \ OK }
  159.     TargetDir := DestDDForm.GetTargetDirectory;
  160.     { Show the hourglass to indicate waiting }
  161.     Screen.Cursor := crHourGlass;
  162.     { Setup to get all selections }
  163.     ThePosition := 1;
  164.     finished := false;
  165.     while not finished do
  166.     begin
  167.       { Call generic file getting routine based on current view}
  168.       case CurrentView of
  169.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  170.              ThePosition );
  171.         2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  172.              ThePosition );
  173.       end;
  174.       { If returns blank string out of selections so exit }
  175.       if CurrentName = '' then finished := true else
  176.       begin
  177.         { If a directory signal error }
  178.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  179.         begin
  180.           if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  181.            +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  182.           begin
  183.             ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  184.              TargetDir );
  185.           end;
  186.         end
  187.         else
  188.         begin
  189.           Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  190.         end;
  191.       end;
  192.     end;
  193.     { Reset to normal cursor }
  194.     Screen.Cursor := crDefault;
  195.   end;
  196.   { Reset to the original directory }
  197.   ChDir( TheOldString );
  198. end;
  199.  
  200. { Delphi wrote this, use it to move files which are selected }
  201. procedure TCCFileMgrForm.BitBtn2Click(Sender: TObject);
  202. var ThePosition  : Integer;       { Loop counter   }
  203.     CurrentName ,                 { Holds work name}
  204.     TheOldString : String;        { Holds Dir      }
  205.     finished     : Boolean;       { Loop control   }
  206.     WorkingDir   : String;        { Holds mod wd   }
  207.     TargetDir    : String;        { target of op   }
  208.     TheResult    : Integer;       { Modal res hold }
  209. begin
  210.   { Get current directory and save it for later }
  211.   GetDir( 0 , TheOldString );
  212.   { Check for need to add trailing \ }
  213.   WorkingDir := TheOldString;
  214.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  215.   { Display the Windows-based directory input form }
  216.   TheResult := DestDDForm.ShowModal;
  217.   { If not cancelled do the copy }
  218.   if TheResult = mrOK then
  219.   begin
  220.     { Get the target directory with \ OK }
  221.     TargetDir := DestDDForm.GetTargetDirectory;
  222.     { Show the hourglass to indicate waiting }
  223.     Screen.Cursor := crHourGlass;
  224.     { Set up to get all current selections }
  225.     ThePosition := 1;
  226.     finished := false;
  227.     while not finished do
  228.     begin
  229.       { Call generic file getting routine based on current view}
  230.       case CurrentView of
  231.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  232.              ThePosition );
  233.         2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  234.              ThePosition );
  235.       end;
  236.       { If returns blank string then out of selections }
  237.       if CurrentName = '' then finished := true else
  238.       begin
  239.         { If a directory signal error }
  240.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  241.         begin
  242.           if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir +
  243.            '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  244.             ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  245.              TargetDir );
  246.         end
  247.         else
  248.         begin
  249.           Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  250.         end;
  251.       end;
  252.       { Reset to normal cursor }
  253.       Screen.Cursor := crDefault;
  254.     end;
  255.   end;
  256.   { Reset to the original directory }
  257.   ChDir( TheOldString );
  258.   if CurrentView = 1 then { Reset icon display if in view }
  259.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  260. end;
  261.  
  262. { Delphi wrote this, use it to delete files which are selected }
  263. procedure TCCFileMgrForm.BitBtn3Click(Sender: TObject);
  264. var ThePosition  : Integer;       { Loop counter   }
  265.     CurrentName ,                 { Holds work name}
  266.     TheOldString : String;        { Holds Dir      }
  267.     finished     : Boolean;       { Loop control   }
  268.     WorkingDir   : String;        { Holds mod wd   }
  269. begin
  270.   { Get current directory and save it for later }
  271.   GetDir( 0 , TheOldString );
  272.   { Check for need to add trailing \ }
  273.   WorkingDir := TheOldString;
  274.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  275.   { Set up to do loop for selected files }
  276.   ThePosition := 1;
  277.   finished := false;
  278.   while not finished do
  279.   begin
  280.     { Call generic file getting routine based on current view}
  281.     case CurrentView of
  282.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  283.            ThePosition );
  284.       2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  285.            ThePosition );
  286.     end;
  287.     { if returns blank string out of selections }
  288.     if CurrentName = '' then finished := true else
  289.     begin
  290.       { If its a directory signal error }
  291.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  292.       begin
  293.         if MessageDlg( 'Delete Directory ' + CurrentName + '?' , mtConfirmation,
  294.          mbYesNoCancel , 0 ) = mrYes then
  295.         begin
  296.           ScrollBox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  297.           Scrollbox1.TheFWB.RemoveDirectory( Currentname );
  298.         end;
  299.       end
  300.       else
  301.       begin
  302.         { Otherwise get confirmation message and if OKed delete file }
  303.         if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  304.          mbYesNoCancel , 0 ) = mrYes then
  305.         begin
  306.           ScrollBox1.TheFWB.DeleteTheFile( Currentname );
  307.         end;
  308.       end;
  309.     end;
  310.   end;
  311.   if CurrentView = 1 then { Reset icon display if in view }
  312.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  313. end;
  314.  
  315. { Delphi wrote this; use it to rename selected files }
  316. procedure TCCFileMgrForm.BitBtn4Click(Sender: TObject);
  317. var ThePosition  : Integer;       { Loop counter   }
  318.     CurrentName ,                 { Holds work name}
  319.     TheOldString : String;        { Holds Dir      }
  320.     finished     : Boolean;       { Loop control   }
  321.     WorkingDir   : String;        { Holds mod wd   }
  322. begin
  323.   { Get current directory for later }
  324.   GetDir( 0 , TheOldString );
  325.   { Check for need to add trailing \ }
  326.   WorkingDir := TheOldString;
  327.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  328.   { Set up to do loop for selected files }
  329.   ThePosition := 1;
  330.   finished := false;
  331.   while not finished do
  332.   begin
  333.     { Call generic file getting routine based on current view}
  334.     case CurrentView of
  335.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  336.            ThePosition );
  337.       2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  338.            ThePosition );
  339.     end;
  340.     { If returns blank string then out of selections }
  341.     if CurrentName = '' then finished := true else
  342.     begin
  343.       { Otherwise set up the opendialog with filename and caption }
  344.       OpenDialog1.Filename := ExtractFilename( CurrentName );
  345.       { Use this to prevent error from changing directories }
  346.       OpenDialog1.Options := [ofNoChangeDir];
  347.       OpenDialog1.Title := 'Rename File';
  348.       { If not cancelled then do rename or signal error }
  349.       if OpenDialog1.Execute then
  350.       begin
  351.         ScrollBox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  352.       end;
  353.     end;
  354.   end;
  355.   if CurrentView = 1 then { Reset icon display if in view }
  356.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  357. end;
  358.  
  359. { Delphi wrote this; use it to make a new directory under current one }
  360. procedure TCCFileMgrForm.BitBtn5Click(Sender: TObject);
  361. begin
  362.   { Set up the dialog to get the new directory name }
  363.   OpenDialog2.FileName := '*.*';
  364.   OpenDialog2.Title := 'Enter Directory Name';
  365.   if OpenDialog1.Execute then
  366.   begin
  367.     { If not cancelled make new directory }
  368.     Scrollbox1.TheFWB.CreateNewDirectory( OpenDialog1.Filename );
  369.   end;
  370.   if CurrentView = 1 then { Reset icon display if in view }
  371.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  372. end;
  373.  
  374. { Delphi wrote this; use it to handle refreshing the scrollbox }
  375. procedure TCCFileMgrForm.FormPaint(Sender: TObject);
  376. var CurrentDirectory : String; { Get current dir }
  377. begin
  378.   { If updated, do refresh }
  379.   if ScrollBox1.IconsNeedRefreshing then
  380.   begin
  381.     Scrollbox1.ClearTheFIPs;
  382.     ScrollBox1.IconsNeedRefreshing := false;
  383.     GetDir( 0 , CurrentDirectory );
  384.     { Force trailing backslash }
  385.     CurrentDirectory := ScrollBox1.TheFWB.ForceTrailingBackSlash(
  386.      CurrentDirectory );
  387.     { Set the label to the new directory }
  388.     Label1.Caption := UpperCase( CurrentDirectory );
  389.     { Do the update }
  390.     ScrollBox1.GetIconsForEntireDirectory( CurrentDirectory );
  391.   end;
  392. end;
  393.  
  394. { Delphi wrote this; use it to reset the current view Icons/List }
  395. procedure TCCFileMgrForm.BitBtn8Click(Sender: TObject);
  396. var TheOldString : String; { Use to get current directory }
  397. begin
  398.   { Reset currentview }
  399.   if CurrentView = 1 then CurrentView := 2 else
  400.    CurrentView := 1;
  401.   { either show the windows boxes or the scrollbox }
  402.   case CurrentView of
  403.     1 : begin
  404.           { Make the listboxes invisible by changing align and width }
  405.           FileListBox1.Visible := false;
  406.           FileListBox1.Align := alNone;
  407.           FileListBox1.Width := 0;
  408.           DirectoryListBox1.Visible := false;
  409.           DirectoryListBox1.align := alNone;
  410.           DirectoryListBox1.Width := 0;
  411.           { Keep them from getting mouse clicks }
  412.           FileListBox1.Enabled := false;
  413.           DirectoryListBox1.Enabled := false;
  414.           { Have the scrollbox get mouse and be seen  by resetting align/wid}
  415.           Scrollbox1.align := alClient;
  416.           Scrollbox1.width := Panel1.Width - 32;
  417.           ScrollBox1.Enabled := true;
  418.           { Tell the scrollbox to repaint itself just in case }
  419.           ScrollBox1.Update;
  420.         end;
  421.     2 : begin
  422.           { Make the listboxes visible by resetting align and width}
  423.           FileListBox1.Visible := true;
  424.           DirectoryListBox1.Visible := true;
  425.           DirectoryListBox1.width := 145;
  426.           DirectoryListBox1.align := alLeft;
  427.           FileListBox1.align := alClient;
  428.           FileListBox1.Width := Panel1.Width - 32 - DirectoryListBox1.Width;
  429.           { Have them getting mouse clicks }
  430.           FileListBox1.Enabled := true;
  431.           DirectoryListBox1.Enabled := true;
  432.           { Have the scrollbox not get mouse and not be seen via align/width}
  433.           ScrollBox1.Enabled := false;
  434.           ScrollBox1.Visible := false;
  435.           ScrollBox1.align := alNone;
  436.           ScrollBox1.Width := 0;
  437.         end;
  438.   end;
  439.   Invalidate;
  440. end;
  441.  
  442. { Delphi wrote this; use it to do a file search display }
  443. procedure TCCFileMgrForm.BitBtn9Click(Sender: TObject);
  444. var CurrentDirectory : String; { Holds current directory }
  445. begin
  446.   { Set up and run the search dialog }
  447.   OpenDialog2.FileName := '*.*';
  448.   { if not cancelled do the search }
  449.   if OpenDialog2.Execute then
  450.   begin
  451.     { Get current directory }
  452.     GetDir( 0 , CurrentDirectory );
  453.     { Force trailing backslash }
  454.     CurrentDirectory :=
  455.      ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentDirectory );
  456.     { display recursive search results }
  457.     Scrollbox1.DisplayRecursiveSearchResults(
  458.      CurrentDirectory + ExtractFileName( OpenDialog2.Filename ));
  459.     Label1.Caption := 'Search Results for ' + CurrentDirectory +
  460.      ExtractFileName( OpenDialog2.FileName );
  461.   end;
  462. end;
  463.  
  464. { Delphi wrote this; use it to set a file's properties }
  465. procedure TCCFileMgrForm.BitBtn6Click(Sender: TObject);
  466. var ThePosition  : Integer;       { Loop counter   }
  467.     CurrentName ,                 { Holds work name}
  468.     TheOldString : String;        { Holds Dir      }
  469.     finished     : Boolean;       { Loop control   }
  470.     WorkingDir   : String;        { Holds mod wd   }
  471. begin
  472.   { Get current directory for later }
  473.   GetDir( 0 , TheOldString );
  474.   ThePosition := 1;
  475.   { Check for need to add trailing \ }
  476.   Workingdir := TheOldString;
  477.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  478.   { Call generic file getting routine based on current view}
  479.   case CurrentView of
  480.     1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  481.          ThePosition );
  482.     2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  483.          ThePosition );
  484.   end;
  485.   { If nothing selected then abort (gets ..!) }
  486.   if CurrentName = '' then
  487.   begin
  488.     MessageDlg( 'No File Selected!' , mtError , [mbOK] , 0 );
  489.     exit;
  490.   end
  491.   else
  492.   begin
  493.     { Otherwise set up the properties form and show it }
  494.     CCFMPropsForm.WorkingFileName := CurrentName;
  495.     CCFMPropsForm.ThePosition := ThePosition;
  496.     CCFMPropsForm.BitBtn4.Enabled := true;
  497.     CCFMPropsForm.Initialize;
  498.     CCFMPropsForm.ShowModal;
  499.   end;
  500.   if CurrentView = 1 then { Reset icon display if in view }
  501.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  502. end;
  503.  
  504. { Delphi wrote this; use it to drag and drop files for copying }
  505. procedure TCCFileMgrForm.BitBtn1DragDrop(Sender, Source: TObject; X,
  506.   Y: Integer);
  507. var CurrentName ,                 { Holds work name}
  508.     WorkingDir ,
  509.     TheOldString : String;        { Holds Dir      }
  510.     TargetDir    : String;        { target of op   }
  511.     TheResult    : Integer;       { Modal res hold }
  512.     Counter_1    : Integer;
  513. begin
  514.   { Make sure source is indeed a FileIconPanel }
  515.   if Source is TIconFileListbox then
  516.   begin
  517.     with Source as TIconFileListBox do
  518.     begin
  519.      { Get current directory and save it for later }
  520.      GetDir( 0 , TheOldString );
  521.      WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( TheOldString );
  522.      { Display the Windows-based directory input form }
  523.      TheResult := DestDDForm.ShowModal;
  524.      { If not cancelled do the copy }
  525.      if TheResult = mrOK then
  526.      begin
  527.        for Counter_1 := 1 to Items.Count do
  528.        begin
  529.          if Selected[ Counter_1 - 1 ] then
  530.          begin
  531.             CurrentName := WorkingDIr + Items[ Counter_1 - 1 ];
  532.             { Get the target directory with \ OK }
  533.             TargetDir := DestDDForm.GetTargetDirectory;
  534.             { If a directory signal and do recursive operation }
  535.             if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  536.             begin
  537.               if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  538.                +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  539.               begin
  540.                 ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  541.                  TargetDir );
  542.               end;
  543.             end
  544.             else
  545.             begin
  546.               { Do the copy }
  547.               Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  548.             end;
  549.             { Reset to the original directory }
  550.             ChDir( TheOldString );
  551.           end;
  552.         end;
  553.       end;
  554.     end;
  555.     FileListBox1.Update;
  556.     exit;
  557.   end;
  558.   if TheIOManager.WasSHIFTPressed then
  559.   begin
  560.     BitBtn1Click( Source );
  561.     exit;
  562.   end;
  563.   with Source as TFileIconPanel do
  564.   begin
  565.     { Get current directory and save it for later }
  566.     GetDir( 0 , TheOldString );
  567.     { Display the Windows-based directory input form }
  568.     TheResult := DestDDForm.ShowModal;
  569.     { If not cancelled do the copy }
  570.     if TheResult = mrOK then
  571.     begin
  572.       CurrentName := FTheName;
  573.       { Get the target directory with \ OK }
  574.       TargetDir := DestDDForm.GetTargetDirectory;
  575.       { If a directory signal and do recursive operation }
  576.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  577.       begin
  578.         if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  579.          +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  580.         begin
  581.           ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  582.            TargetDir );
  583.         end;
  584.       end
  585.       else
  586.       begin
  587.         { Do the copy }
  588.         Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  589.       end;
  590.       { Reset to the original directory }
  591.       ChDir( TheOldString );
  592.     end;
  593.   end;
  594. end;
  595.  
  596. { Delphi wrote this; use it to generically OK DnD from FIPs }
  597. procedure TCCFileMgrForm.BitBtn1DragOver(Sender, Source: TObject; X,
  598.   Y: Integer; State: TDragState; var Accept: Boolean);
  599. begin
  600.   { Only accept from FileIconPanel components }
  601.   if ( Source is TFileIconPanel ) or
  602.      ( Source is TIconFileListBox ) then Accept := true else Accept := false;
  603. end;
  604.  
  605. { Delphi wrote this; use it to accept Drag and Drop moving }
  606. procedure TCCFileMgrForm.BitBtn2DragDrop(Sender, Source: TObject; X,
  607.   Y: Integer);
  608. var CurrentName ,                 { Holds work name}
  609.     WorkingDir ,
  610.     TheOldString : String;        { Holds Dir      }
  611.     TargetDir    : String;        { target of op   }
  612.     TheResult       : Integer;    { Modal res hold }
  613.     Counter_1   : Integer;
  614. begin
  615.   { Make sure source is indeed a FileIconPanel }
  616.   if Source is TIconFileListbox then
  617.   begin
  618.     with Source as TIconFileListBox do
  619.     begin
  620.       { Get current directory and save it for later }
  621.       GetDir( 0 , TheOldString );
  622.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( TheOldString );
  623.       { Display the Windows-based directory input form }
  624.       TheResult := DestDDForm.ShowModal;
  625.       for Counter_1 := 1 to Items.Count do
  626.       begin
  627.         if Selected[ Counter_1 - 1 ] then
  628.         begin
  629.           { If not cancelled do the copy }
  630.           if TheResult = mrOK then
  631.           begin
  632.             CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  633.             { Get the target directory with \ OK }
  634.             TargetDir := DestDDForm.GetTargetDirectory;
  635.             { If a directory signal and do recursive operation }
  636.             if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  637.             begin
  638.               if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir
  639.                +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  640.               begin
  641.                 ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  642.                  TargetDir );
  643.               end;
  644.             end
  645.             else
  646.             begin
  647.               { Do the copy }
  648.               Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  649.             end;
  650.             { Reset to the original directory }
  651.             ChDir( TheOldString );
  652.           end;
  653.         end;
  654.       end;
  655.     end;
  656.     FileListBox1.Update;
  657.     exit;
  658.   end;
  659.   if TheIOManager.WasSHIFTPressed then
  660.   begin
  661.     BitBtn2Click( Source );
  662.     exit;
  663.   end;
  664.   with Source as TFileIconPanel do
  665.   begin
  666.     { Get current directory and save it for later }
  667.     GetDir( 0 , TheOldString );
  668.     { Display the Windows-based directory input form }
  669.     TheResult := DestDDForm.ShowModal;
  670.     { If not cancelled do the copy }
  671.     if TheResult = mrOK then
  672.     begin
  673.       { Get the target directory with \ OK }
  674.       TargetDir := DestDDForm.GetTargetDirectory;
  675.       { If Copyfile returns false an error occurred }
  676.       CurrentName := FTheName;
  677.       { If a directory signal and do recursion }
  678.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  679.       begin
  680.         if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir +
  681.          '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  682.           ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  683.            TargetDir );
  684.       end
  685.       else
  686.       begin  { Do the move }
  687.         Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  688.         ChDir( TheOldString );
  689.       end;
  690.       { Refresh display }
  691.       ScrollBox1.Update;
  692.     end;
  693.   end;
  694. end;
  695.  
  696. { Delphi wrote this; use it to do drag and drop deletes }
  697. procedure TCCFileMgrForm.BitBtn3DragDrop(Sender, Source: TObject; X,
  698.   Y: Integer);
  699. var WorkingDir ,
  700.     CurrentName : String;  { Holds work name}
  701.     Counter_1   : Integer;
  702. begin
  703.   { Make sure source is indeed a FileIconPanel }
  704.   if Source is TIconFileListbox then
  705.   begin
  706.     with Source as TIconFileListBox do
  707.     begin
  708.       GetDir( 0 , WorkingDir );
  709.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  710.       for Counter_1 := 1 to Items.Count do
  711.       begin
  712.         if Selected[ Counter_1 - 1 ] then
  713.         begin
  714.           CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  715.           { If a directory signal and do recursive operation }
  716.           if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  717.           begin
  718.             if MessageDlg( 'Delete Directory ' + CurrentName +'?',
  719.              mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  720.             begin
  721.               ScrollBox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  722.               Scrollbox1.TheFWB.RemoveDirectory( CurrentName );
  723.             end;
  724.           end
  725.           else
  726.           begin
  727.             if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  728.              mbYesNoCancel , 0 ) = mrYes then
  729.             begin
  730.               Scrollbox1.TheFWB.DeleteTheFile( CurrentName );
  731.             end;
  732.           end;
  733.         end;
  734.       end;
  735.     end;
  736.     FileListBox1.Update;
  737.     exit;
  738.   end;
  739.   if TheIOManager.WasSHIFTPressed then
  740.   begin
  741.     BitBtn3Click( Source );
  742.     exit;
  743.   end;
  744.   with Source as TFileIconPanel do
  745.   begin
  746.     CurrentName := FTheName;
  747.     { If its a directory signal and do recursive delete }
  748.     if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  749.     begin
  750.       if MessageDlg( 'Delete Directory ' + CurrentName + '?' , mtConfirmation ,
  751.        mbYesNoCancel , 0 ) = mrYes then
  752.       begin
  753.         Scrollbox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  754.         Scrollbox1.TheFWB.RemoveDirectory( CurrentName );
  755.       end;
  756.     end
  757.     else
  758.     begin
  759.       { Otherwise get confirmation message and if OKed delete file }
  760.       if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  761.        mbYesNoCancel , 0 ) = mrYes then
  762.       begin
  763.         Scrollbox1.TheFWB.DeleteTheFile( CurrentName );
  764.       end;
  765.     end;
  766.     { Refresh Display }
  767.     Scrollbox1.Update;
  768.   end;
  769. end;
  770.  
  771. { Delphi wrote this; use it to do drag and drop renames }
  772. procedure TCCFileMgrForm.BitBtn4DragDrop(Sender, Source: TObject; X,
  773.   Y: Integer);
  774. var WorkingDir ,
  775.     CurrentName : String;  { Holds work name}
  776.     Counter_1   : Integer;
  777. begin
  778.   { Make sure source is indeed a FileIconPanel }
  779.   if Source is TIconFileListbox then
  780.   begin
  781.     with Source as TIconFileListBox do
  782.     begin
  783.       GetDir( 0 , WorkingDir );
  784.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  785.       for Counter_1 := 1 to Items.Count do
  786.       begin
  787.         if Selected[ Counter_1 - 1 ] then
  788.         begin
  789.           CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  790.           { Otherwise set up the opendialog with filename and caption }
  791.           OpenDialog2.Filename := ExtractFilename( CurrentName );
  792.           { Use this to prevent error from changing directories }
  793.           OpenDialog2.Options := [ofNoChangeDir];
  794.           OpenDialog2.Title := 'Rename File';
  795.           { If not cancelled then do rename or signal error }
  796.           if OpenDialog2.Execute then
  797.           begin
  798.             Scrollbox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  799.           end;
  800.         end;
  801.       end;
  802.     end;
  803.     FileListBox1.Update;
  804.     exit;
  805.   end;
  806.   if TheIOManager.WasSHIFTPressed then
  807.   begin
  808.     BitBtn4Click( Source );
  809.     exit;
  810.   end;
  811.   with Source as TFileIconPanel do
  812.   begin
  813.     CurrentName := FTheName;
  814.     { If a directory signal error }
  815.     { Otherwise set up the opendialog with filename and caption }
  816.     OpenDialog2.Filename := ExtractFilename( CurrentName );
  817.     { Use this to prevent error from changing directories }
  818.     OpenDialog2.Options := [ofNoChangeDir];
  819.     OpenDialog2.Title := 'Rename File';
  820.     { If not cancelled then do rename or signal error }
  821.     if OpenDialog2.Execute then
  822.     begin
  823.       Scrollbox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  824.     end;
  825.     { Refresh the display }
  826.     ScrollBox1.Update;
  827.   end;
  828. end;
  829.  
  830. procedure TCCFileMgrForm.BitBtn10Click(Sender: TObject);
  831. var TheCCFMForm : TCCFileMgrForm;
  832. begin
  833.   TheCCFMForm := TCCFileMgrForm.Create( Application );
  834.   TheCCFMForm.Show;
  835. end;
  836.  
  837. procedure TCCFileMgrForm.FormDestroy(Sender: TObject);
  838. begin
  839.   { Release the IO Manager }
  840.   if assigned( TheIOManager) then
  841.   begin
  842.     TheIOManager.Free;
  843.     TheIOManager := nil;
  844.   end;
  845. end;
  846.  
  847. { Delphi wrote this; use it to trap function keys and other keypresses }
  848. procedure TCCFileMgrForm.FormKeyDown(Sender: TObject; var Key: Word;
  849.   Shift: TShiftState);
  850. begin
  851.   { Key contains a virtual key code; use it to invoke the IOMgr methods }
  852.   case Key of
  853.     VK_F1 : TheIOManager.OnF1Pressed( Sender , Key , Shift );
  854.     VK_F2 : TheIOManager.OnF2Pressed( Sender , Key , Shift );
  855.     VK_F3 : TheIOManager.OnF3Pressed( Sender , Key , Shift );
  856.     VK_F4 : TheIOManager.OnF4Pressed( Sender , Key , Shift );
  857.     VK_F5 : TheIOManager.OnF5Pressed( Sender , Key , Shift );
  858.     VK_F6 : TheIOManager.OnF6Pressed( Sender , Key , Shift );
  859.     VK_F7 : TheIOManager.OnF7Pressed( Sender , Key , Shift );
  860.     VK_F8 : TheIOManager.OnF8Pressed( Sender , Key , Shift );
  861.     VK_F9 : TheIOManager.OnF9Pressed( Sender , Key , Shift );
  862.     VK_F10 : TheIOManager.OnF10Pressed( Sender , Key , Shift );
  863.     VK_F11 : TheIOManager.OnF11Pressed( Sender , Key , Shift );
  864.     VK_F12 : TheIOManager.OnF12Pressed( Sender , Key , Shift );
  865.   end;
  866. end;
  867.  
  868. end.
  869.